#include "stdio.h"
#include "stdint.h"
//#include "utils.h"
#include <stdio.h>
#include <string.h>
#include "sign_ali.h"


static void do_ali_topic(struct ali_topic *topic,char *pkey,char *dev_name)
{
    memset(topic,0x00,sizeof(struct ali_topic));
    sprintf(topic->topic_pub_ota_infor,ALINK_TOPIC_OTA_INFO_PUB,pkey,dev_name);
    sprintf(topic->topic_pub_post,ALINK_TOPIC_PUB,pkey,dev_name);
    sprintf(topic->topic_sub_get,ALINK_TOPIC_SUB_GET,pkey,dev_name);
    sprintf(topic->topic_pub_ota_pgs,ALINK_TOPIC_OTA_PGS_PUB,pkey,dev_name);
    sprintf(topic->topic_sub_ota_update,ALINK_TOPIC_OTA_UPDATE_SUB,pkey,dev_name);
    sprintf(topic->topic_sub_set,ALINK_TOPIC_SUB_SET,pkey,dev_name);
    sprintf(topic->topic_sub_post_reply,ALINK_TOPIC_PROP_POSTRSP,pkey,dev_name);

}

void do_iotx_sign_mqtt(iotx_mqtt_region_types_t region,
                        iotx_sign_mqtt_t *sign_mqtt,
                        struct ali_topic *topic,
                        char *pkey,char *dev_name,
                        char *psecret,char *dsecret )
{
    iotx_dev_meta_info_t meta_info;

    memset(&meta_info, 0, sizeof(iotx_dev_meta_info_t));
    //下面的代码是将上面静态定义的设备身份信息赋值给meta_info
    memcpy(meta_info.product_key, pkey, strlen(pkey));
    memcpy(meta_info.product_secret, psecret, strlen(psecret));
    memcpy(meta_info.device_name,dev_name, strlen(dev_name));
    memcpy(meta_info.device_secret, dsecret, strlen(dsecret));
    //调用签名函数，生成MQTT连接时需要的各种数据
    if (sign_mqtt)
        IOT_Sign_MQTT(region, &meta_info, sign_mqtt);
    if (topic)
        do_ali_topic(topic,pkey,dev_name);

}

void do_iotx_sign_regnwl_mqtt(iotx_mqtt_region_types_t region,
                        iotx_sign_mqtt_t *sign_mqtt,
                        char *pkey,char *dev_name,
                        char *psecret)
{
    iotx_dev_meta_info_t meta_info;

    memset(&meta_info, 0, sizeof(iotx_dev_meta_info_t));
    //下面的代码是将上面静态定义的设备身份信息赋值给meta_info
    memcpy(meta_info.product_key, pkey, strlen(pkey));
    memcpy(meta_info.product_secret, psecret, strlen(psecret));
    memcpy(meta_info.device_name,dev_name, strlen(dev_name));

    //调用签名函数，生成MQTT连接时需要的各种数据
    if (sign_mqtt)
        IOT_Sign_regnwl_MQTT(region, &meta_info, sign_mqtt);

}

void do_iotx_sign_connwl_mqtt(iotx_mqtt_region_types_t region,
                        iotx_sign_mqtt_t *sign_mqtt,
                        struct ali_topic *topic,
                        char *pkey,char *dev_name,
                        char *psecret,char *token,char *client_id )
{

    iotx_dev_meta_info_t meta_info;

    memset(&meta_info, 0, sizeof(iotx_dev_meta_info_t));
    //下面的代码是将上面静态定义的设备身份信息赋值给meta_info
    memcpy(meta_info.product_key, pkey, strlen(pkey));
    memcpy(meta_info.product_secret, psecret, strlen(psecret));
    memcpy(meta_info.device_name,dev_name, strlen(dev_name));
    memcpy(meta_info.token,token, strlen(token));
     memcpy(meta_info.client_id,client_id, strlen(client_id));
    //调用签名函数，生成MQTT连接时需要的各种数据
    if (sign_mqtt)
        IOT_Sign_connwl_MQTT(region, &meta_info, sign_mqtt);
    if (topic)
        do_ali_topic(topic,pkey,dev_name);

}
